﻿using Photo.Core.Dtos.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Photo.Core.Extensions
{
    /// <summary>
    /// 分页扩展
    /// </summary>
    public static class PagedQueryableExtension
    {
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="query"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public static async Task<PagedList<TEntity>> ToPagedListAsync<TEntity>(this ISugarQueryable<TEntity> query, PagedInput page)
        {
            RefAsync<int> count = 0;
            List<TEntity> result = await query.ToPageListAsync(page.PageIndex, page.PageSize, count);
            return new PagedList<TEntity>
            {
                TotalCount = count.Value,
                List = result
            };
        }

    }
}
